import 'dart:ui';

class ZSSizeFit {
  static double physicalWidth = 0;
  static double physicalHeight = 0;
  static double screenWidth = 0;
  static double screenHeight = 0;
  static double dpr = 0;
  static double statusHeight = 0;

  static double rpx = 0;
  static double px = 0;

  static void initialize({double standardSize = 750}) {
    // 1.手机的物理分辨率
    physicalWidth = window.physicalSize.width;
    physicalHeight = window.physicalSize.height;
    // print('分辨率:$physicalWidth * $physicalHeight');

    //2.手机屏幕的大小(逻辑分辨率) 放在这里会报错(context还没初始化完)
    // var width2 = MediaQuery.of(context).size.width;
    // var height2 = MediaQuery.of(context).size.height;

    //3.另一种获取屏幕的大小,获取dpr
    dpr = window.devicePixelRatio;
    screenWidth = physicalWidth / dpr;
    screenHeight = physicalHeight / dpr;
    // print('屏幕宽高:$screenWidth * $screenHeight');

    //4.状态栏高度
    statusHeight = window.padding.top / dpr;
    // print('状态栏高度:$statusHeight');

    //5.计算rpx大小
    rpx = screenWidth / standardSize;
    px = screenWidth / standardSize * 2;
  }

  static double setRpx(double size) {
    return rpx * size;
  }

  static double setPx(double size) {
    return px * size;
  }
}
